// @ts-ignore
import {Config} from "@/libs/config";
import {WxmpUtil} from "@/utils";

export class HttpUtil {


    static request = (options: any) :Promise<any> => {
        const headers =     () => {

            return {
                'content-type': 'application/json',
                "wxmpAppId":  uni.getStorageSync("wxmpAppId") ,
                "authorization": "Bearer " +  uni.getStorageSync("AccessToken")
            }
        }


        options.header =  headers();

        return new Promise((resolve, reject) => {
            // @ts-ignore
			uni.request(options).then(res => resolve(res.data))
                .catch((error: any) => reject(error))

        });
    }

    static getAjax = (url: string, data = {}): Promise< any>  => {
        const options = {
            method: 'GET',
            data,
            url: Config.BASE_URL + url
        }
        return this.request(options)
    }

    static postAjax = (url: string, data = {}) => {
        const options = {
            method: 'POST',
            data,
            url: Config.BASE_URL + url
        }
        return this.request(options)
    }
    static putAjax = (url: string, data = {}) => {
        const options = {
            method: 'PUT',
            data,
            url: Config.BASE_URL + url
        }
        return this.request(options)
    }


    static delAjax = (url: string, data = {}) => {
        const options = {
            method: 'DELETE',
            data,
            url: Config.BASE_URL + url
        }
        return this.request(options)
    }
}